#ifndef OBJECTS_PAGEOBJECT_H
#define OBJECTS_PAGEOBJECT_H

#include <QtCore/qobject.h>
#include <QtCore/qrect.h>

#include "../doker.h"

class TextObject;

class PageObject : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int number READ number)
    Q_PROPERTY(int n READ number)
    Q_PROPERTY(qreal width READ width WRITE setWidth)
    Q_PROPERTY(qreal w READ width WRITE setWidth)
    Q_PROPERTY(qreal height READ height WRITE setHeight)
    Q_PROPERTY(qreal h READ height WRITE setHeight)
public:
    explicit PageObject(QObject *parent = 0);
    static void reset();
    void linkToSource(const QString &fileName, int lineNumber)
    { m_sourceFileName = fileName; m_sourceLineNumber = lineNumber; }

    qreal width() const { return m_width; }
    void setWidth(qreal w) { m_width = w; }
    int pixelWidth() const { return toPixels(m_width); }

    qreal height() const { return m_height; }
    void setHeight(qreal h);
    int pixelHeight() const {return toPixels(m_height); }

    QRectF frameRect() const;
    QRectF pageRect() const { return QRectF(0, m_originY, m_width, m_height); }
    QRect pixelFrameRect() const;
    QRect pixelPageRect() const;

    int number() const { return m_number; }

    Q_INVOKABLE void area(qreal left, qreal top, qreal right, qreal bottom)
    { m_areas.append(QRectF(left, top, right - left, bottom - top)); }
    int areaCount() const { return m_areas.count(); }
    QRectF areaRect(int index) const;
    QRect pixelAreaRect(int index) const;

    void addText(TextObject *textObject);
    int textCount() const { return m_texts.count(); }
    TextObject *text(int index) const;

    qreal originY() const { return m_originY; }
    int pixelOriginY() const { return toPixels(m_originY); }

private:
    QString          m_sourceFileName;
    int              m_sourceLineNumber;
    static int       m_number;
    static qreal     m_offsetY;
    qreal            m_originY;
    qreal            m_width;
    qreal            m_height;
    QList<QRectF>    m_areas;

    QList<TextObject*>   m_texts;
};

#endif // OBJECTS_PAGEOBJECT_H
